package com.dps.recommend.layer.rank;

import com.dps.recommend.ann.LayerAnn;
import com.dps.recommend.beans.DpsRequest;
import com.dps.recommend.beans.ProcessInterface;
import com.dps.recommend.beans.RecItemDps;
import com.dps.recommend.enums.LayerEnum;
import com.dps.recommend.utils.DateUtil;
import com.dps.recommend.utils.DpsBaseService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 处理综合得到并且按照时间排序
 */
@Service
@LayerAnn(layer = LayerEnum.RANK)
class DpsTimeRank extends DpsBaseService implements ProcessInterface {
    @Override
    public <R extends RecItemDps> List doProcess(DpsRequest dpsRequest, List<R> list) {
        list = list.stream().sorted((m1, m2) -> {
            Date m2Date = DateUtil.parseDateString(m2.getCreateTime());
            Date m1Date = DateUtil.parseDateString(m1.getCreateTime());
            return Long.compare(m2Date.getTime(), m1Date.getTime());
        }).collect(Collectors.toList());

        return list;
    }

}
